import React,{Suspense} from 'react';
import {
    BrowserRouter,
    Route,
    Routes,
    Navigate
} from "react-router-dom";
import routes from "./RouterConfig";
import{ ROUTERTYPES}  from "../types/route.d"
function RouterView() {
    const renderRoute=(arr:ROUTERTYPES[])=>{
        return arr.map((item,index)=>{
            return item.path?<Route key={index} path={item.path} element={<item.component />}>
                {
                    item.children&&renderRoute(item.children)
                }
            </Route>
            :<Route key={index} path={item.from} element={<Navigate to={item.to} />}></Route>
        })
    }
    return (
            <Suspense>
                <BrowserRouter>
                <Routes>
                    {
                        renderRoute(routes)
                    }
                </Routes>
                </BrowserRouter>
            </Suspense>
    )
}

export default RouterView
